package com.springboot.idempotence.busi;

import com.springboot.idempotence.redis.AutoIdempotent;
import com.springboot.idempotence.redis.TokenService;
import com.springboot.idempotence.redis.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class BusinessController {
    @Resource
    private TokenService tokenService;
    @Autowired
    private BusinessService businessService;

    @PostMapping("/get/token")
    public String getToken() {
        String token = tokenService.createToken();
        if (StringUtils.isEmpty(token)) {
            return "ERR";
        }
        return token;
    }

    @AutoIdempotent
    @PostMapping("/test/Idempotence")
    public String testIdempotence() {
        System.out.println("方法中!");
        String result = businessService.testIndempotence();
        if (StringUtils.isEmpty(result)) {
            return null;
        }
        return result;
    }
}
